package edu.cs.usask.ca.silver.plugin.rcp.dialogs.simulations;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * this class implements the Vensim simulation options in terms of dialog.
 * 
 * @author Yudi Xue
 * 
 */
public class RunVensimSimulationDialog extends Dialog {

	private static String simName;
	private static Text nameText;

	public RunVensimSimulationDialog(Shell parentShell) {
		super(parentShell);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("Vensim Simulation Option");
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		final Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));

		Label nameLabel = new Label(composite, SWT.NONE);
		nameLabel.setText("Simulation Name:");

		nameText = new Text(composite, SWT.BORDER);
		GridData gridData = new GridData();
		gridData.horizontalAlignment = SWT.FILL;
		gridData.grabExcessHorizontalSpace = true;
		nameText.setLayoutData(gridData);
		nameText.setText("output");

		return composite;

	}

	@Override
	protected void okPressed() {
		if (nameText.getText().equals("")) {
			MessageDialog.openError(getShell(), "Invalid simulation name",
					"Please specify a name for the simulation");
			return;
		}
		simName = nameText.getText();
		super.okPressed();
	}

	public float startTime() {
		return 0;
	}

	public float endTime() {
		return 100;
	}

	/**
	 * return the simulation name input.
	 * 
	 * @return String representation of Simulation name.
	 */
	public String simName() {
		return simName;
	}
}